package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrapp.base.service.MOmsTspePlanCycleService;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsTspePlanCycleMapper;
import com.wicket.okrapp.dal.po.mbg.OmsTspePlanCycle;
import com.wicket.okrapp.base.service.dto.req.*;
//import com.wicket.okrapp.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;

import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsTspePlanCycleServiceImpl
  extends ServiceImpl<OmsTspePlanCycleMapper, OmsTspePlanCycle>
  implements MOmsTspePlanCycleService {

  @Autowired
  OmsTspePlanCycleMapper omsTspePlanCycleMapper;
/**
   * 3-2-03查评价模板周期安排列表[2338]
   * gen by moon at 10/15/2022, 10:02:50 PM
   */
 @Trace(operationName = "3-2-03查评价模板周期安排列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsTspePlanCycle>  queryEvaTepCyclePlanList(QueryEvaTepCyclePlanListReq reqDto) {
     
        try {
            QueryWrapper<OmsTspePlanCycle> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTspePlanCycle.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsTspePlanCycle>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-2-03批量增评价模板安排周期[2357]
   * gen by moon at 10/15/2022, 10:02:51 PM
   */
 @Trace(operationName = "3-2-03批量增评价模板安排周期")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchAddEvaTepPlanCycle(List<OmsTspePlanCycle> omsTspePlanCycle) {
     
      if(omsTspePlanCycle==null || omsTspePlanCycle.size()==0){
        return false;
      }
      
      return super.saveBatch(omsTspePlanCycle.stream().map(item->{
       item.setPlanCycleId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
item.setSubjectLifeCycle("EDITING");
item.setIsArchive("FALSE");
item.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
item.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
item.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
item.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
item.setIsValid("FALSE");
item.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
item.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
          return item;
      }).collect(Collectors.toList()));
  }
/**
   * 3-2-03修改评价模板周期安排[2392]
   * gen by moon at 10/15/2022, 10:02:53 PM
   */
 @Trace(operationName = "3-2-03修改评价模板周期安排")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updateEvaTepCyclePlan(OmsTspePlanCycle omsTspePlanCycle) {
     
        return super.updateById(omsTspePlanCycle);
  }
/**
   * 3-2-03新增评价模板周期安排[2407]
   * gen by moon at 10/15/2022, 10:02:54 PM
   */
 @Trace(operationName = "3-2-03新增评价模板周期安排")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addEvaTepCyclePlan(OmsTspePlanCycle omsTspePlanCycle) {
     omsTspePlanCycle.setPlanCycleId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsTspePlanCycle.setSubjectLifeCycle("EDITING");
omsTspePlanCycle.setIsArchive("N");
omsTspePlanCycle.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsTspePlanCycle.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsTspePlanCycle.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsTspePlanCycle.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsTspePlanCycle.setIsValid("FALSE");
omsTspePlanCycle.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsTspePlanCycle.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsTspePlanCycle)){
        return omsTspePlanCycle.getPlanCycleId();
     }else {
        return "-1";
     }
    
  }
/**
   * 3-2-03查评价模板周期安排详情[2498]
   * gen by moon at 4/24/2023, 12:54:15 AM
   */
 @Trace(operationName = "3-2-03查评价模板周期安排详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsTspePlanCycle  queryEvaTepCyclePlanDetail(QueryEvaTepCyclePlanDetailReq reqDto) {
     
        try {
         
            QueryWrapper<OmsTspePlanCycle> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsTspePlanCycle> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsTspePlanCycle retData = retList.get(0);
                
                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 3-2-03批量改评价模板周期安排[2499]
   * gen by moon at 10/15/2022, 10:02:57 PM
   */
 @Trace(operationName = "3-2-03批量改评价模板周期安排")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchUpdateEvaTepCyclePlan(List<OmsTspePlanCycle> omsTspePlanCycle) {
     
      if(omsTspePlanCycle==null || omsTspePlanCycle.size()==0){
        return false;
      }
        return super.saveOrUpdateBatch(omsTspePlanCycle);
      
  }
/**
   * 3-2-03批量查询评价模板安排周期[2867]
   * gen by moon at 10/15/2022, 10:02:59 PM
   */
 @Trace(operationName = "3-2-03批量查询评价模板安排周期")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsTspePlanCycle>  batchQueryEvaTepPlanCycle(BatchQueryEvaTepPlanCycleReq reqDto) {
     
        try {
            QueryWrapper<OmsTspePlanCycle> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            if(reqDto.getEvaTepCyclePlanList()==null || reqDto.getEvaTepCyclePlanList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("eva_obj_target_cycle_id", reqDto.getEvaTepCyclePlanList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTspePlanCycle.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsTspePlanCycle>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-2-03批量查询要求安排周期[3156]
   * gen by moon at 10/15/2022, 10:03:01 PM
   */
 @Trace(operationName = "3-2-03批量查询要求安排周期")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsTspePlanCycle>  batchQueryRequestArrangeCycle(BatchQueryRequestArrangeCycleReq reqDto) {
     
        try {
            QueryWrapper<OmsTspePlanCycle> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            if(reqDto.getEvaTepPlanCycleList()==null || reqDto.getEvaTepPlanCycleList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("eva_obj_target_cycle_id", reqDto.getEvaTepPlanCycleList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTspePlanCycle.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsTspePlanCycle>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-2-03批量查询模板安排要求目标子周期[4129]
   * gen by moon at 10/15/2022, 10:03:03 PM
   */
 @Trace(operationName = "3-2-03批量查询模板安排要求目标子周期")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsTspePlanCycle>  batchQueryTempArrangeRequireSubEvaObjTargetCycle(BatchQueryTempArrangeRequireSubEvaObjTargetCycleReq reqDto) {
     
        try {
            QueryWrapper<OmsTspePlanCycle> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            if(reqDto.getEvaTepCyclePlanList()==null || reqDto.getEvaTepCyclePlanList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("eva_obj_target_cycle_id", reqDto.getEvaTepCyclePlanList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTspePlanCycle.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsTspePlanCycle>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-2-03查询要求安排周期列表[4228]
   * gen by moon at 10/15/2022, 10:03:05 PM
   */
 @Trace(operationName = "3-2-03查询要求安排周期列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsTspePlanCycle>  queryRequestArrangeCycleList(QueryRequestArrangeCycleListReq reqDto) {
     
        try {
            QueryWrapper<OmsTspePlanCycle> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTspePlanCycle.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTspePlanCycle.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsTspePlanCycle>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-2-03批量删要求安排周期[4229]
   * gen by moon at 10/15/2022, 10:03:07 PM
   */
 @Trace(operationName = "3-2-03批量删要求安排周期")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchDeleteRequestArrangeCycle(List<String> reqDto) {
     
          if(reqDto==null || reqDto.size()==0){
            return false;
          }
          
          return super.removeByIds(reqDto);
  }
/**
   * 3-3-03批量删评价模板安排周期[4611]
   * gen by moon at 10/15/2022, 10:03:09 PM
   */
 @Trace(operationName = "3-3-03批量删评价模板安排周期")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchDeleteEvaTepPlanCycle(List<String> reqDto) {
     
          if(reqDto==null || reqDto.size()==0){
            return false;
          }
          
          return super.removeByIds(reqDto);
  }

}

